const urlParams = new URLSearchParams(window.location.search);
const token = localStorage.getItem('Admin-Token') || urlParams.get('token');
if(!token) {
  alert('无权限');
  window.close()
}
const BASE_URL = 'http://localhost:8080';
window.we = {
  fetch: (url, init) => fetch(`${BASE_URL}${url}`, {
    ...init, headers: {
      'X-Sys': 'msg',
      'Content-Type': 'application/json', 'Authorization': `Bearer ${ token }`
    }
  }).then(async response => {
    const promise = await response.json();
    if(!response.ok) throw new Error(promise?.message || ('网络响应不正常: ' + response.statusText));
    return promise;
  })
}
